package com.demo2;

import java.io.PipedOutputStream;
import java.sql.Statement;

public class ArrayUtil {
    //私有化构造方法
    //目的:为了不让外界创建他的对象
    private ArrayUtil() {
    }

    //需要定义为静态的，方便调用
    public static String printArr(int[] arr) {
        StringBuffer buffer = new StringBuffer();
        buffer.append('[');
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                buffer.append(arr[i]);
            } else {
                buffer.append(arr[i]).append(",");
            }
        }
        buffer.append("]");
        return buffer.toString();
    }

    public static double getAverage(double[] arr) {
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum / arr.length;
    }
}
